import java.util.*;

public class ScheduleManager {
    private List<Schedule> schedules = new ArrayList<>();
    private HallManager hallManager;
    private MovieManager movieManager;

    public ScheduleManager(HallManager hallManager, MovieManager movieManager) {
        this.hallManager = hallManager;
        this.movieManager = movieManager;
    }

    // 获取所有场次
    public List<Schedule> getSchedules() {
        return schedules;
    }

    // 添加场次，防止重复ID
    public boolean addSchedule(Schedule schedule) {
        if (findScheduleById(schedule.getScheduleId()) != null) return false;
        schedules.add(schedule);
        return true;
    }

    // 根据场次编号删除场次
    public boolean removeScheduleById(String id) {
        Iterator<Schedule> it = schedules.iterator();
        while (it.hasNext()) {
            Schedule s = it.next();
            if (s.getScheduleId().equals(id)) {
                it.remove();
                return true;
            }
        }
        return false;
    }

    // 根据片名查找所有相关场次
    public List<Schedule> findSchedulesByMovieName(String movieName) {
        List<Schedule> result = new ArrayList<>();
        for (Schedule s : schedules) {
            if (s.getMovie().getName().equals(movieName)) {
                result.add(s);
            }
        }
        return result;
    }

    // 根据场次编号查找场次
    public Schedule findScheduleById(String id) {
        for (Schedule s : schedules) {
            if (s.getScheduleId().equals(id)) {
                return s;
            }
        }
        return null;
    }
} 